Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System Tests: FIM - Synchronization process #2443

Merged
merged 28 commits into from
Feb 11, 2022

Conversation

CamiRomero
Copy link
Contributor

@CamiRomero CamiRomero commented Jan 13, 2022

Related issue
2389

Description

The test check that FIM currently work when we have a folder monitored and we performed some action like create the file, modify or delete files, the manager receives the changes

Configuration options

In order to run the test, first the environment located in /test/system/provisioning/one_manager_agent must be enabled with:
sudo ansible-playbook -i inventory.yml playbook.yml --extra-vars='{"wazuh_branch": "4.2"}'

Logs example

Tests

Run Results Date By Notes
R1 🟢 13/01/2021 @CamiRomero
R2 🟢 13/01/2021 @CamiRomero
R3 🟢 13/01/2021 @CamiRomero

Tests

  • Proven that tests pass when they have to pass.
  • Proven that tests fail when they have to fail.
  • Python codebase satisfies PEP-8 style style guide. pycodestyle --max-line-length=120 --show-source --show-pep8 file.py.
  • Python codebase is documented following the Google Style for Python docstrings.

Deblintrake09
Deblintrake09 previously approved these changes Jan 18, 2022
Comment on lines 4 to 5


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add documentation

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, Add the changelog.md

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in commit 2c97b y 2413d

Comment on lines 28 to 48
def create_folder(folder_path):
# Create folder
host_manager.run_command('wazuh-agent1', f'mkdir {folder_path}')

# Create file
host_manager.run_command('wazuh-agent1', f'touch {folder_path}/{folder_path}.txt')


def clean_logs():
host_manager.clear_file(host='wazuh-manager', file_path=os.path.join(WAZUH_LOGS_PATH, 'ossec.log'))
host_manager.clear_file(host='wazuh-agent1', file_path=os.path.join(WAZUH_LOGS_PATH, 'ossec.log'))


def wait_for_fim_scan_end(folder_path):
try:
HostMonitor(inventory_path=inventory_path,
messages_path=messages_path[2],
tmp_path=tmp_path).run()
finally:
host_manager.run_command('wazuh-agent1', f'rm -rf {folder_path}')

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could these methods be parameterized and added outside of the test to be used by other tests in the future or would it cause problems?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in commit 5972a

Comment on lines 121 to 129
host_manager.run_command('wazuh-agent1', f'rm -rf {folder_path}')

try:
# Run the callback checks for the ossec.log
HostMonitor(inventory_path=inventory_path,
messages_path=messages_path[0],
tmp_path=tmp_path).run()
finally:
host_manager.run_command('wazuh-agent1', f'rm -rf {folder_path}')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it could be a problem? Why you remove 2 times the same file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in commit 79d05

Comment on lines 4 to 5


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, Add the changelog.md

@damarisg damarisg changed the title 2389 system test for fim synchronization process System Tests: FIM - Synchronization process Jan 23, 2022
@CamiRomero
Copy link
Contributor Author

CamiRomero commented Jan 24, 2022

Run Results Date By Notes
R1 🟢 24/01/2022 @CamiRomero
R2 🟢 24/01/2022 @CamiRomero
R3 🟢 24/01/2022 @CamiRomero

@CamiRomero
Copy link
Contributor Author

Run Results Date By Notes
R1 🟢 26/01/2022 @CamiRomero
R2 🟢 26/01/2022 @CamiRomero
R3 🟢 26/01/2022 @CamiRomero

Copy link
Contributor

@Deblintrake09 Deblintrake09 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved

Tests

Run Results Date By Notes
R1 🟢 26/01/2021 @Deblintrake09
R2 🟢 26/01/2021 @Deblintrake09
R3 🟢 26/01/2021 @Deblintrake09

Deblintrake09
Deblintrake09 previously approved these changes Jan 26, 2022
Comment on lines 22 to 24
def clean_logs(host_manager):
host_manager.clear_file(host='wazuh-manager', file_path=os.path.join(WAZUH_LOGS_PATH, 'ossec.log'))
host_manager.clear_file(host='wazuh-agent1', file_path=os.path.join(WAZUH_LOGS_PATH, 'ossec.log'))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use clean_environment method, please?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in commit 91ef4

"""Clears a series of files on target hosts managed by a host manager
Args:
host_manager (object): a host manager object with not None inventory_path
target_files (dict): a dictionary of tuples, each with the host and the path of the file to clear.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
target_files (dict): a dictionary of tuples, each with the host and the path of the file to clear.
target_files (dict): a list of tuples, each with the host and the path of the file to clear.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in commit 0f4c9

Deblintrake09
Deblintrake09 previously approved these changes Jan 28, 2022
@Deblintrake09
Copy link
Contributor

Deblintrake09 commented Jan 28, 2022

Tests

Test Results Date By Notes
test_files_cud.py 🟢 28/01/2021 @Deblintrake09
test_files_cud.py 🟢 28/01/2021 @Deblintrake09
test_files_cud.py 🟢 28/01/2021 @Deblintrake09


docker_network: "cluster_net"

image: "dontpanicat/debian:buster"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not use third party docker images

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we applied the suggested changes, we note that there is a conflict with access to the remote host via ssh. We will open an Issue to work on that.

Comment on lines 69 to 75
def test_file_cud(folder_path, case):
'''
The test will monitor a directory.
Finally, it will verify that the FIM event is generated
in agent and manager side.
'''
messages = messages_path[0]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test_ documentation does not apply to Schema 2.0.
Let's document the test as we did with other integration tests, or same you did with the module doc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in commit 2622c

@snaow snaow merged commit b8ea5e7 into master Feb 11, 2022
@snaow snaow deleted the 2389-System-test-for-fim-synchronization-process branch February 11, 2022 09:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FIM Files Events: System test for FIM synchronization process (1)
4 participants